package a00_ImageGame.Test;

import java.util.Random;

/**
 * @Author quan
 * @Description TODO
 * @Date 2023/3/6 21:00
 */
public class ArrayUse {
    public static void main(String[] args) {
        //-----------打乱一维数组的顺序----------
        int[] arr = {0,1,2,3,4,5,6,7,8};
        //获取随机索引0-9范围内
        Random random = new Random();
        int index = random.nextInt(arr.length);
        //将一维数组中的元素值与索引值进行交换
        for (int i = 0; i < arr.length; i++) {
            int temp = arr[index];
            arr[index] = arr[i];
            arr[i] = temp;
        }
      /*  for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }*/
        //-------将一维数组的值放入二维数组中--------
        int[][] arr1 = new int[3][3];
        int n = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                arr1[i][j] = arr[n];
                n++;
            }
        }
        //遍历二维数组
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr1.length; j++) {
                System.out.print(arr1[i][j]+" ");
            }
            System.out.println();
        }
    }
}
